package com.huika.dealontop.control.myinfo.holder;

import android.content.Context;
import android.graphics.Paint;
import android.view.View;
import android.widget.TextView;

import com.huika.dealontop.R;
import com.huika.dealontop.control.base.extend.BaseViewHolder;
import com.huika.dealontop.support.domain.OrderDetailBean;
import com.huika.dealontop.utils.DateTimeTool;
import com.huika.dealontop.utils.UIUtils;
import com.huika.huikalib.utils.StringUtils;

/**
 * Author: Victor Wu <br/>
 * Email: victor-wu*foxmail.com <br/>
 * Time: 2015/11/19 16:14 <br/>
 * Description: 团购券 条目 holder
 */
public class CouponItemHolder extends BaseViewHolder<OrderDetailBean.DataBean>{

    private TextView mCouponCode;
    private TextView mCouponState;
    private TextView mCouponTime;

    public CouponItemHolder(Context context) {
        super(context);
    }

    @Override
    protected View initView() {
        View view = View.inflate(UIUtils.getContext(), R.layout.item_order_detail_coupon, null);
        mCouponCode = (TextView) view.findViewById(R.id.tv_coupon_item_couponCode);
        mCouponState = (TextView) view.findViewById(R.id.tv_coupon_item_couponState);
        mCouponTime = (TextView) view.findViewById(R.id.tv_coupon_item_couponTime);
        return view;
    }

    @Override
    protected void refreshView(OrderDetailBean.DataBean data) {
        int state = data.getCouponStatus();
        mCouponCode.setText(StringUtils.spaceFormatString(data.getCouponCode()));
        mCouponCode.getPaint().setFlags((state == 1 || state == 2) ? Paint.HINTING_OFF : Paint.STRIKE_THRU_TEXT_FLAG); //中划线
        mCouponState.setText(getOrderStateStr(state));
        mCouponState.setTextColor(2 != state ? UIUtils.getColor(R.color.color_999999)
                : UIUtils.getColor(R.color.color_FD712C));
        mCouponTime.setText(DateTimeTool.dmyDate(data.getCouponTime()));
    }

    private String getOrderStateStr(int state){
        //2未使用，3已使用，4：退款中，5：已退款，6已过期（可退款,扣订单支付金额20%，可消费)
        if(1 == state)
            return UIUtils.getString(R.string.myorder_list_filter_nopay);
        if(2 == state)
            return UIUtils.getString(R.string.myorder_list_filter_nouse);
        if(3 == state)
            return UIUtils.getString(R.string.myorder_list_has_use);
        if(4 == state)
            return UIUtils.getString(R.string.refund_in_process);
        if(5 == state)
            return UIUtils.getString(R.string.myorder_list_has_refund);
        if(6 == state)
            return UIUtils.getString(R.string.myorder_list_has_expired);
        return "";
    }

}
